package com.app.controller;

import com.app.model.TrainIntentionModel;

import com.app.service.TrainIntentionService;
import com.app.util.CommonHelp;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//培训机构信息
@RestController
@Controller
@RequestMapping("/jiuquan/trainIntention")
public class TrainIntentionController {

    @Autowired
    private TrainIntentionService trainIntentionService;

    //新增和修改
    @PostMapping("/addAndUpdateTrainIntention")
    public Result addAndUpdateTrainIntention(@RequestBody TrainIntentionModel trainIntentionModel) {
        TrainIntentionModel trainIntention = trainIntentionService.getById(trainIntentionModel.getId());
        if (trainIntention != null) {
            trainIntentionModel.setUpdateTime(CommonHelp.getNowTimestamp());
            trainIntentionService.updateById(trainIntentionModel);
            return Result.success("修改成功");
        } else {
            trainIntentionModel.setCreateTime(CommonHelp.getNowTimestamp());
            trainIntentionService.save(trainIntentionModel);
            return Result.success("添加成功");
        }
    }

}
